const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  // const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}
const formatDate = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  return [year, month, day].map(formatNumber).join('-')
}
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function getAcademybyNum(num){
  var Academy
  switch (num) {
    case 0:Academy = "长江大学";break;
    case 1:Academy = "研究生院";break;
    case 2:Academy = "文学院";break;
    case 3:Academy = "外国语学院";break;
    case 4:Academy = "艺术学院";break;
    case 5:Academy = "教育与体育学院";break;
    case 6:Academy = "第一临床医学院";break;
    case 7:Academy = "经济与管理学院";break;
    case 8:Academy = "第二临床医学院";break;
    case 9:Academy = "法学院";break;    
    case 10:Academy = "马克思主义学院";break;
    case 11:Academy = "信息与数学学院";break;
    case 12:Academy = "物理与光电工程学院";break;
    case 13:Academy = "化学与环境工程学院";break;
    case 14:Academy = "生命科学学院";break;
    case 15:Academy = "机械工程学院";break;
    case 16:Academy = "电子信息学院";break; 
    case 17:Academy = "计算机科学学院";break;
    case 18:Academy = "城市建设学院";break;
    case 19:Academy = "资源与环境学院";break;
    case 20:Academy = "地球物理与石油资源学院";break;
    case 21:Academy = "地球科学学院";break;
    case 22:Academy = "石油工程学院";break;
    case 23:Academy = "农学院";break;
    case 24:Academy = "园艺园林学院";break;
    case 25:Academy = "动物科学学院";break;
    case 26:Academy = "艺术与传媒学院";break;
    default: Academy = "选择学院";
  } 
  return Academy
}
const collegeDB=wx.cloud.database().collection('collegeData')
function AcademybyNum(num) {
  let that = this
   if(num>26){
       return "选择学院"
   }else{
     collegeDB.where({
       college:"长江大学"
     }).get({
       success:function(res){     
         console.log(res.data[0])    
         let allAcademy = res.data[0].allAcademy
         for(var i=0;i<allAcademy.length;i++){
           console.log(allAcademy[i].academyNum)
           if(num ==allAcademy[i].academyNum ){
             console.log(allAcademy[i].academy)
             return allAcademy[i].academy
           }
         }
       }
     })
   }
}

module.exports = {
  formatTime: formatTime,
  formatDate:formatDate,
  getAcademybyNum: getAcademybyNum,
  AcademybyNum:AcademybyNum,
}